package com.ncloud.resman.service.impl;

import com.ncloud.resman.entity.DeviceSub;
import com.ncloud.resman.mapper.SwitchSubMapper;
import com.ncloud.resman.service.DeviceSwitchSubService;
import com.ncloud.resman.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shiqiang on 2017/8/15.
 */
@Service
public class DeviceSwitchSubServiceImpl implements DeviceSwitchSubService {
    @Autowired
    private SwitchSubMapper switchSubMapper;
    @Autowired
    private SequenceService sequenceService;

    @Override
    public int insertDeviceSubSwitch (DeviceSub deviceSub){
        if(deviceSub.getSubId() == null){
            Long id = sequenceService.getSequence("sub_id_seq");
            deviceSub.setSubId(id);
        }
        deviceSub.setCreateDate(new Date());
        return switchSubMapper.insertSwitchSub(deviceSub);
    }

    @Override
    public int updateDeviceSubSwitch(DeviceSub deviceSub) {
        deviceSub.setUpdateDate(new Date());
        return switchSubMapper.updateSwitchSub(deviceSub);
    }

    @Override
    public int deleteSwitchSub(Long deviceId) {
        return switchSubMapper.deleteSwitchSub(deviceId);
    }

    @Override
    public int updateSwitchSubPurpose(DeviceSub deviceSub) {
        return switchSubMapper.updateSwitchSubPurpose(deviceSub);
    }

	@Override
	public int updateSwitchSubSubNoInfo(DeviceSub deviceSub) {
		return switchSubMapper.updateSwitchSubSubNoInfo(deviceSub);
	}

	@Override
	public List<DeviceSub> exportDeviceSwitchSub(Long deviceId) {
		return switchSubMapper.exportDeviceSwitchSub(deviceId);
	}
}
